<template>
  <div class="mobile-asset-list common-mobile-view">
    <div class="total-asset">
      <span class="title">总资产</span>
      <span class="value">{{ formatAmount(assetStore.totalAsset) }}</span>
    </div>

    <asset-query />

    <el-empty v-if="assetStore.assetRecordList.length === 0" />

    <div v-else class="asset-list">
      <asset-card v-for="(item, index) in assetStore.assetList"
                  :key="index" :item="item"/>
    </div>

    <draggable-button @click="addClick"/>
  </div>
</template>

<script setup lang="ts">
import AssetQuery from '@/components/Asset/AssetQuery.vue'
import AssetCard from '@/components/Asset/AssetCard.vue'
import DraggableButton from '@/components/Common/DraggableButton.vue'
import { useAssetStore } from '@/store/asset.ts'
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { formatAmount } from 'vue3-common/utils/numberUtil'

const assetStore = useAssetStore()
const router = useRouter()

onMounted(async () => {
  await assetStore.queryAssetList()
})

const addClick = () => {
  assetStore.assetApiType = 'ADD'
  assetStore.currentAssetRecord = assetStore.getEmptyAsset()
  router.push({ name: 'AssetDetailId', params: { id: 0 } })
}
</script>

<style lang="scss">
.mobile-asset-list {
  display: flex;
  flex-direction: column;
  gap: 10px;

  .total-asset {
    align-self: center;
    display: flex;
    align-items: center;
    gap: 10px;

    .title {
      font-size: 1.5rem;
    }

    .value {
      font-weight: bold;
      font-size: 1.8rem;
      color: var(--el-color-primary);
    }
  }

  .asset-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
}
</style>
